Creating the Twitter CSV files

Write new csv files with all the libraries with Twitter handles

  • 1 file for the National libraries (3 libraries)
  • 1 file for university libraries (27 libraries)
  • 1 file for public libraries (21 libraries)

Functions


In [1]:
import csv
import json

#import & export CSV

def impCSV(input_file):
    '''
    input_file = csv with keys: "URL", "Twitter"
    output = list of dictionaries
    '''
    f = open(input_file, 'r')
    d = csv.DictReader(f)
    LoD = []   # list of dictionaries
    for row in d:
        LoD.append(row)
    f.close()
    return LoD

def exp2CSV(listOfDict, filename):
    '''
    arguments = list of dictionaries, filename
    output = saves file to cwd (current working directory)
    '''
    outputfile = filename
    keyz = listOfDict[0].keys()
    f = open(outputfile,'w')
    dict_writer = csv.DictWriter(f,keyz)
    dict_writer.writer.writerow(keyz)
    dict_writer.writerows(listOfDict)
    f.close()


# extracting the tweeting libraries form the files

def twiLibCSV(listname, newFilename):
    '''
    input: the name of the list and a Filename
    output: saves a new LoD with only the tweeting libraries 
            and prints out a status update
    '''
    LoD_2 = []
    for i in listname:
        LoD = impCSV(i)
        for i in LoD:
            if i['Twitter'] != '@_@':
                i['Twitter'] = i['Twitter'].lower()  # the Twitter names given on the websites 
                LoD_2.append(i)                      # and the screen_names in the Twitter accounts 
                                                     # vary sometimes regarding to upper- and lower case!
    exp2CSV(LoD_2, newFilename)
    print 'The new csv file was saved as', newFilename, 'to your current working directory!'
    print
    print 'In this file are', len(LoD_2), 'libraries:'
    print
    print json.dumps(LoD_2, indent=1)
    #return LoD_2

Function calls for the three groups


In [2]:
uniLib = ['DBS_4_UB.csv']
natLiB = ['DBS_NatBib.csv']
pubLib = ['DBS_1.csv', 'DBS_2.csv']

In [4]:
twiLibCSV(natLiB, 'NatBibTwitter.csv')


The new csv file was saved as NatBibTwitter2.csv to your current working directory!

In this file are 3 libraries:

[
 {
  "URL": "http://www.bsb-muenchen.de", 
  "Ort": "M\u00fcnchen", 
  "DBS-ID": "AG012", 
  "Name": "M\u00fcnchen BSB", 
  "Twitter": "bsb_muenchen"
 }, 
 {
  "URL": "http://www.dnb.de", 
  "Ort": "Frankfurt/M", 
  "DBS-ID": "AG292", 
  "Name": "Frankfurt/M DNB", 
  "Twitter": "dnb_aktuelles"
 }, 
 {
  "URL": "http://www.staatsbibliothek-berlin.de", 
  "Ort": "Berlin", 
  "DBS-ID": "AK001", 
  "Name": "Berlin SBB", 
  "Twitter": "sbb_news"
 }
]

In [5]:
twiLibCSV(uniLib, 'UniBibTwitter.csv')


The new csv file was saved as UniBibTwitter2.csv to your current working directory!

In this file are 27 libraries:

[
 {
  "URL": "http://www.bis.uni-oldenburg.de", 
  "Ort": "Oldenburg", 
  "DBS-ID": "AH715", 
  "Name": "Oldenburg UB", 
  "Twitter": "ub_oldenburg"
 }, 
 {
  "URL": "http://www.hsu-bibliothek.de", 
  "Ort": "Hamburg", 
  "DBS-ID": "DB900", 
  "Name": "Hamburg HSU", 
  "Twitter": "hsubib"
 }, 
 {
  "URL": "http://www.ub.hu-berlin.de", 
  "Ort": "Berlin", 
  "DBS-ID": "AD011", 
  "Name": "Berlin UB Humboldt", 
  "Twitter": "ubhumboldtuni"
 }, 
 {
  "URL": "http://www.bibliothek.kit.edu", 
  "Ort": "Karlsruhe", 
  "DBS-ID": "AH090", 
  "Name": "Karlsruhe KIT-BIB", 
  "Twitter": "kitbibliothek"
 }, 
 {
  "URL": "http://kiz.uni-ulm.de", 
  "Ort": "Ulm/Do", 
  "DBS-ID": "AA289", 
  "Name": "Ulm/Do kiz (UB)", 
  "Twitter": "kizuulm"
 }, 
 {
  "URL": "http://www.sub.uni-goettingen.de", 
  "Ort": "G\u00f6ttingen", 
  "DBS-ID": "AF007", 
  "Name": "G\u00f6ttingen SuUB", 
  "Twitter": "subugoe"
 }, 
 {
  "URL": "http://www.ub.rub.de", 
  "Ort": "Bochum", 
  "DBS-ID": "AB294", 
  "Name": "Bochum UB", 
  "Twitter": "ubbochum"
 }, 
 {
  "URL": "http://www.tu-dresden.de/slub/", 
  "Ort": "Dresden", 
  "DBS-ID": "AE088", 
  "Name": "Dresden SLUB", 
  "Twitter": "slubdresden"
 }, 
 {
  "URL": "http://www.suub.uni-bremen.de", 
  "Ort": "Bremen", 
  "DBS-ID": "AA046", 
  "Name": "Bremen SuUB", 
  "Twitter": "elibbremen"
 }, 
 {
  "URL": "http://www.sub.uni-hamburg.de", 
  "Ort": "Hamburg", 
  "DBS-ID": "AC018", 
  "Name": "Hamburg SuUB", 
  "Twitter": "stabihh"
 }, 
 {
  "URL": "http://www.ub.tu-berlin.de", 
  "Ort": "Berlin", 
  "DBS-ID": "AA083", 
  "Name": "Berlin UBTU", 
  "Twitter": "ub_tu_berlin"
 }, 
 {
  "URL": "http://www.tub.tu-harburg.de", 
  "Ort": "Hamburg", 
  "DBS-ID": "AE830", 
  "Name": "Hamburg TU", 
  "Twitter": "tubhh"
 }, 
 {
  "URL": "http://www.ulb.uni-bonn.de", 
  "Ort": "Bonn", 
  "DBS-ID": "AL005", 
  "Name": "Bonn UuLB", 
  "Twitter": "ulbbonn"
 }, 
 {
  "URL": "http://www.ub.uni-bayreuth.de/", 
  "Ort": "Bayreuth", 
  "DBS-ID": "AH703", 
  "Name": "Bayreuth UB", 
  "Twitter": "ubbayreuth_info"
 }, 
 {
  "URL": "http://www.ub.uni-bielefeld.de", 
  "Ort": "Bielefeld", 
  "DBS-ID": "AB361", 
  "Name": "Bielefeld UB", 
  "Twitter": "ub_bi"
 }, 
 {
  "URL": "http://www.biblio.tu-bs.de", 
  "Ort": "Braunschweig", 
  "DBS-ID": "AD084", 
  "Name": "Braunschweig UBTU", 
  "Twitter": "unibib_bs"
 }, 
 {
  "URL": "http://www.bibliothek.uni-wuerzburg.de", 
  "Ort": "W\u00fcrzburg", 
  "DBS-ID": "AF020", 
  "Name": "W\u00fcrzburg UB", 
  "Twitter": "ub_wue"
 }, 
 {
  "URL": "http://www.ub.uni-dortmund.de", 
  "Ort": "Dortmund", 
  "DBS-ID": "AA290", 
  "Name": "Dortmund UB", 
  "Twitter": "unibib"
 }, 
 {
  "URL": "http://www.ub.uni-duisburg-essen.de", 
  "Ort": "Duisburg-Essen", 
  "DBS-ID": "DE100", 
  "Name": "Duisburg-Essen UB", 
  "Twitter": "ubdue"
 }, 
 {
  "URL": "http://www.ub.uni-erlangen.de/", 
  "Ort": "Erlangen-N", 
  "DBS-ID": "AL029", 
  "Name": "Erlangen-N UB", 
  "Twitter": "ub_fau"
 }, 
 {
  "URL": "http://www.tib.uni-hannover.de", 
  "Ort": "Hannover", 
  "DBS-ID": "AH089", 
  "Name": "Hannover UB", 
  "Twitter": "tibub"
 }, 
 {
  "URL": "http://www.ub.uni-kassel.de", 
  "Ort": "Kassel", 
  "DBS-ID": "AA034", 
  "Name": "Kassel UB", 
  "Twitter": "ubkassel"
 }, 
 {
  "URL": "http://www.ub.uni-leipzig.de", 
  "Ort": "Leipzig", 
  "DBS-ID": "AE015", 
  "Name": "Leipzig UB", 
  "Twitter": "ubleipzig"
 }, 
 {
  "URL": "http://www.ub.uni-mainz.de", 
  "Ort": "Mainz", 
  "DBS-ID": "AH077", 
  "Name": "Mainz UB", 
  "Twitter": "ubmainz"
 }, 
 {
  "URL": "http://www.uni-marburg.de/bis/", 
  "Ort": "Marburg/L", 
  "DBS-ID": "AH004", 
  "Name": "Marburg/L UB", 
  "Twitter": "unibib_mr"
 }, 
 {
  "URL": "http://www.uni-regensburg.de/bibliothek", 
  "Ort": "Regensburg", 
  "DBS-ID": "AJ355", 
  "Name": "Regensburg UB", 
  "Twitter": "ubreg"
 }, 
 {
  "URL": "http://www.zbsport.de", 
  "Ort": "K\u00f6lnSportHS", 
  "DBS-ID": "DC072", 
  "Name": "K\u00f6lnSportHS ZB", 
  "Twitter": "zbsport"
 }
]

In [3]:
twiLibCSV(pubLib, 'OeBibTwitter.csv')


The new csv file was saved as OeBibTwitter.csv to your current working directory!

In this file are 21 libraries:

[
 {
  "URL": "http://www.stadtbibliothek-bielefeld.de", 
  "Ort": "Bielefeld", 
  "DBS-ID": "AE131", 
  "Name": "Bielefeld StB", 
  "Twitter": "stb_bielefeld"
 }, 
 {
  "URL": "http://www.stadtbibliothek-bremen.de", 
  "Ort": "Bremen", 
  "DBS-ID": "AH478", 
  "Name": "Bremen StB", 
  "Twitter": "stabi_bremen"
 }, 
 {
  "URL": "http://www.stadtbibliothek.essen.de", 
  "Ort": "Essen", 
  "DBS-ID": "AE064", 
  "Name": "Essen StB", 
  "Twitter": "stbessen"
 }, 
 {
  "URL": "http://www.stbib-koeln.de/", 
  "Ort": "K\u00f6ln", 
  "DBS-ID": "AJ380", 
  "Name": "K\u00f6ln StB", 
  "Twitter": "stbibkoeln"
 }, 
 {
  "URL": "http://www.duesseldorf.de/stadtbuechereien", 
  "Ort": "D\u00fcsseldorf", 
  "DBS-ID": "AE362", 
  "Name": "D\u00fcsseldorf StB", 
  "Twitter": "stadtbueduedorf"
 }, 
 {
  "URL": "http://www.buecherhallen.de", 
  "Ort": "Hamburg", 
  "DBS-ID": "GB722", 
  "Name": "Hamburg H\u00d6B", 
  "Twitter": "hoeb4u"
 }, 
 {
  "URL": "http://www.kulturforum-witten.de/bibliothek", 
  "Ort": "Witten", 
  "DBS-ID": "AJ367", 
  "Name": "Witten StB", 
  "Twitter": "bibliothek_wit"
 }, 
 {
  "URL": "http://www.mediothek-krefeld.de", 
  "Ort": "Krefeld", 
  "DBS-ID": "AD072", 
  "Name": "Krefeld Mediothek", 
  "Twitter": "mediothek"
 }, 
 {
  "URL": "http://www.erlangen.de/bibliothek", 
  "Ort": "Erlangen", 
  "DBS-ID": "GE231", 
  "Name": "Erlangen StB", 
  "Twitter": "stabi_erlangen"
 }, 
 {
  "URL": "http://www.freiburg.de/stadtbibliothek", 
  "Ort": "Freiburg/Br", 
  "DBS-ID": "KS124", 
  "Name": "Freiburg/Br StB", 
  "Twitter": "stabifr"
 }, 
 {
  "URL": "http://stadtbibliothek.goettingen.de", 
  "Ort": "G\u00f6ttingen", 
  "DBS-ID": "AL285", 
  "Name": "G\u00f6ttingen StB", 
  "Twitter": "stabigoe"
 }, 
 {
  "URL": "http://www.stadtbibliothek-neuss.de/", 
  "Ort": "Neuss", 
  "DBS-ID": "AD217", 
  "Name": "Neuss StB", 
  "Twitter": "stbneuss"
 }, 
 {
  "URL": "http://www.salzgitter.de/rathaus/fachdienstuebersicht/stadtbibliothek/index.php ", 
  "Ort": "Salzgitter", 
  "DBS-ID": "AF275", 
  "Name": "Salzgitter StB", 
  "Twitter": "stbsalzgitter"
 }, 
 {
  "URL": "http://www.stadtbibliothek.solingen.de", 
  "Ort": "Solingen", 
  "DBS-ID": "AL157", 
  "Name": "Solingen StB", 
  "Twitter": "stabiso"
 }, 
 {
  "URL": "http://www.stadtbibliothek-chemnitz.de", 
  "Ort": "Chemnitz", 
  "DBS-ID": "AD059", 
  "Name": "Chemnitz StB", 
  "Twitter": "sbchemnitz"
 }, 
 {
  "URL": "http://www.stadtbibliothek-guetersloh.de", 
  "Ort": "G\u00fctersloh", 
  "DBS-ID": "AG371", 
  "Name": "G\u00fctersloh StB", 
  "Twitter": "stabiguetersloh"
 }, 
 {
  "URL": "http://www.stadtbibliothek.mannheim.de", 
  "Ort": "Mannheim", 
  "DBS-ID": "GB850", 
  "Name": "Mannheim StB", 
  "Twitter": "stabi_mannheim"
 }, 
 {
  "URL": "http://www.stb-mh.de", 
  "Ort": "Berlin", 
  "DBS-ID": "WB782", 
  "Name": "Berlin Marzahn ZB", 
  "Twitter": "stadtbibliothek"
 }, 
 {
  "URL": "http://www.stadtbibliothek-mg.de", 
  "Ort": "M\u00f6nchengladbach", 
  "DBS-ID": "AH260", 
  "Name": "M\u00f6nchengladbach StB", 
  "Twitter": "stadtbibmg"
 }, 
 {
  "URL": "http://www.muenster.de/stadt/buecherei", 
  "Ort": "M\u00fcnster", 
  "DBS-ID": "AA447", 
  "Name": "M\u00fcnster StB", 
  "Twitter": "buecherei_ms"
 }, 
 {
  "URL": "http://www.stadtbuecherei-wuerzburg.de", 
  "Ort": "W\u00fcrzburg", 
  "DBS-ID": "AH284", 
  "Name": "W\u00fcrzburg StB", 
  "Twitter": "stabuewuerzburg"
 }
]

In [ ]: